#!/usr/local/bin/python3
# -*- coding: utf-8 -*-

"""
@File    : exp_chart_data.py
@Author  : different
@Time    : 2021-8-10 14:29
@Desc    : 返回饼图数据

"""
from expand.exp_data.exp_base_data import BaseData
from expand.exp_ret_format import interval_equally, fmt_add_time


# 返回饼图数据
class ChartData(BaseData):

    def __init__(self, pk) -> None:
        super().__init__(pk)

    def rating_chart(self):
        rating_result = self.conn.execute(self.rating_sql)
        return [dict(zip(i.keys(), i)) for i in rating_result]

    def price_chart(self):
        min_price = self.conn.execute(self.min_price).first()[0]
        max_price = self.conn.execute(self.max_price).first()[0]
        price_eq = interval_equally(min_price, max_price)
        price_result = self.conn.execute(self.price_sql(price_eq))
        return [dict(zip(i.keys(), i)) for i in price_result]

    def add_time_chart(self):
        add_time_result = self.conn.execute(self.add_time_sql)
        return fmt_add_time([dict(zip(i.keys(), i)) for i in add_time_result])

    def score_chart(self):
        score_result = self.conn.execute(self.score_sql)
        return [dict(zip(i.keys(), i)) for i in score_result]

    def rating_stars(self):
        rating_result = self.conn.execute(self.rating_stars_sql)
        return fmt_add_time([dict(zip(i.keys(), i)) for i in rating_result])

    def top5_chart(self):
        top5_result = self.conn.execute(self.top5_sql)
        return [dict(zip(i.keys(), i)) for i in top5_result]

